package thread.demo.futureTask;

import java.util.concurrent.*;

public class FutureTaskTest001 {
  public static void main(String[] args) throws ExecutionException, InterruptedException {
    FutureTask<String> futureTask = new FutureTask<>(() -> {
      System.out.println("任务开始 ...");
      TimeUnit.SECONDS.sleep(2);
      System.out.println("任务结束 ...");
      return "OK";
    });
    
    ExecutorService executorService = Executors.newFixedThreadPool(1);
    executorService.execute(futureTask);
    
    // 一旦触发取消的状态，就会报异常
//    futureTask.cancel(true);
    System.out.println(futureTask.get());
  }
}
